<?php
class PostsController extends AppController {
	
	var $name = 'Posts' ;
	var $helpers = array ( 'Html' , 'Form' ) ;
	var $uses = array ( 'Post' ) ;
	var $components = array ( 'Acl' ) ;
	
	function add () {
		if (! empty ( $this->data )) {
			$this->Post->data = $this->data ;
			
			if ($this->Post->validates ()) {
				$this->Post->create () ;
				
				if ($this->Post->save ( $this->data )) {
					$acoNode = array ( 'model' => $this->Post->name , 'foreign_key' => $this->Post->id ) ;
					
					$aroNode = array ( 'model' => 'User' , 'foreign_key' => $this->getUserId () ) ;
					
					// User has full control of the post he created 					$this->Acl->allow ( $aroNode, $acoNode, '*' ) ;
				}
			}
		}
	}
}
?>